package com.ruoyi.web.controller.dgw;

import java.util.List;

import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dgw.domain.CowShed;
import com.ruoyi.dgw.service.ICowShedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 牛棚Controller
 * 
 * @author ll
 * @date 2021-12-31
 */
@RestController
@RequestMapping("/dgw/shed")
public class CowShedController extends BaseController
{
    @Autowired
    private ICowShedService cowShedService;

    /**
     * 查询牛棚列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:shed:list')")
    @GetMapping("/list")
    public TableDataInfo list(CowShed cowShed)
    {
        startPage();
        List<CowShed> list = cowShedService.selectCowShedList(cowShed);
        return getDataTable(list);
    }

    /**
     * 导出牛棚列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:shed:export')")
    @Log(title = "牛棚", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CowShed cowShed)
    {
        List<CowShed> list = cowShedService.selectCowShedList(cowShed);
        ExcelUtil<CowShed> util = new ExcelUtil<CowShed>(CowShed.class);
        return util.exportExcel(list, "牛棚数据");
    }

    /**
     * 获取牛棚详细信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:shed:query')")
    @GetMapping(value = "/{cowShedId}")
    public AjaxResult getInfo(@PathVariable("cowShedId") String cowShedId)
    {
        return AjaxResult.success(cowShedService.selectCowShedByCowShedId(cowShedId));
    }

    /**
     * 新增牛棚
     */
    @PreAuthorize("@ss.hasPermi('dgw:shed:add')")
    @Log(title = "牛棚", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CowShed cowShed)
    {

        return toAjax(cowShedService.insertCowShed(cowShed));
    }

    /**
     * 修改牛棚
     */
    @PreAuthorize("@ss.hasPermi('dgw:shed:edit')")
    @Log(title = "牛棚", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CowShed cowShed)
    {
        return toAjax(cowShedService.updateCowShed(cowShed));
    }

    /**
     * 删除牛棚
     */
    @PreAuthorize("@ss.hasPermi('dgw:shed:remove')")
    @Log(title = "牛棚", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cowShedIds}")
    public AjaxResult remove(@PathVariable String[] cowShedIds)
    {
        return toAjax(cowShedService.deleteCowShedByCowShedIds(cowShedIds));
    }
}
